﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Joyintech.DBUtility;
using Joyintech.IDAL.inpiao365;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

namespace Joyintech.SQL2008DAL.inpiao365
{
    public partial class screenings_DAL : AbstractDAL, Iscreenings_DAL
    {
        /// <summary>
        /// 获取影院电影场次信息
        /// </summary>
        /// <param name="movieid">电影ID</param>
        /// <param name="cinemaid">影院ID</param>
        /// <param name="currentdate">放映时间，以某日为单位</param>
        /// <returns></returns>
        public System.Data.DataSet GetList(string movieid, string cinemaid, DateTime currentdate)
        {
            DateTime startdate = currentdate;
            DateTime enddate = currentdate.AddDays(1).AddSeconds(-1);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ScreeningsId,MovieSeatTime,a.MovieId,a.MovieName,a.TheaterRoomId,Price,b.TheaterRoomName,d.MovieType ");
            strSql.Append(" FROM screenings a inner join dbo.theaterRoom b on a.TheaterRoomId=b.TheaterRoomId");
            strSql.Append(" inner join theater c on b.TheaterId=c.TheaterId");
            strSql.Append(" inner join movie d on a.MovieId=d.MovieId");
            strSql.Append(" where a.MovieId={0} and a.TheaterRoomId={1} and a.MovieSeatTime between '{2}' and '{3}'");
            string sql = string.Format(strSql.ToString(), movieid, cinemaid, startdate, enddate);
            Database db = this.CreateDatabase();
            return ExecuteDataSet(db, CommandType.Text, sql);
        }

        /// <summary>
        /// 获得影院的热映电影
        /// </summary>
        /// <param name="theaterid"></param>
        /// <returns></returns>
        public DataSet GetHotMovie(string theaterid)
        {
            
            DateTime currentTime = DateTime.Now.AddMinutes(20);
            StringBuilder sql = new StringBuilder("select distinct (MovieName),movieid theaterName from dbo.screenings a, theater b ,theaterRoom c where a.TheaterRoomId=c.TheaterRoomId and c.TheaterId=b.TheaterId");
            sql.Append(" and b.theaterid=" + theaterid);
            sql.Append(" and a.movieseattime>='"+currentTime+"'" );
            Database db = this.CreateDatabase();
            return ExecuteDataSet(db, CommandType.Text, sql.ToString());
        }
    }
}
